package com.xu.tools.enums;


import com.xu.tools.exception.CommonException;

/**
 * @author xugaun
 * @desc 通用错误码枚举
 */
public enum CommonErrorCodeEnum {
    OK(200, "OK"),
    BAD_REQUEST(400, "Bad Request"),
    INTERNAL_SERVER_ERROR(500, "Internal Server Error"),
    ;

    private final Integer code;
    private final String msg;

    CommonErrorCodeEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    /**
     * 使用错误码枚举, 实例化一个公共异常
     *
     * @return CommonException
     */
    public CommonException exception() {
        return new CommonException(this.code, this.msg);
    }

    /**
     * 直接抛出一个公共异常
     */
    public void throwException() {
        CommonException.throwException(this.code, this.msg);
    }
}
